from fastapi import APIRouter, HTTPException
from app.schemas.generate import GenerateScriptRequest
from app.core.prompt_template import build_prompt
from app.services.llm_chat import chat_with_qwen

router = APIRouter()

@router.post("/generate")
def generate_script(req: GenerateScriptRequest):
    try:
        prompt = build_prompt(req.product, req.cases, req.methods)
        result = chat_with_qwen(prompt)
        return {"result": result}
    except Exception as e:
        raise HTTPException(status_code=500, detail=str(e))
